Skip to content

恢复中断的更新 - SoftUpdateTryRecover

函数简介

zip/rar 更新在提交阶段被中断(存在 update_in_progress.flag)时,尝试从 .ola_update\backup 将文件回滚到更新前状态。

返回结构与 SoftUpdateGetLastStatus 相同(Code / Phase / StatusCode / Detail 等)。回滚成功或无中断标志时通常 Code=1;回滚失败时 Code=0 并带失败详情。

接口名称

SoftUpdateTryRecover

DLL调用

long SoftUpdateTryRecover(string installRoot);

参数说明

参数名类型说明
installRoot字符串安装根目录。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
OlaSoftUpdateLastStatusReturn status = ola.SoftUpdateTryRecover("C:\\App");
if (status.Code == 0) {
    // 回滚失败:status.Message / status.Detail
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
OlaSoftUpdateLastStatusReturn status = ola.SoftUpdateTryRecover(@"C:\App");
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
json_result = ola.SoftUpdateTryRecover(r"C:\App")
# Python SDK 返回 JSON 字符串,需自行解析
java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.OlaSoftUpdateLastStatusReturn;

OLAPlugServer ola = new OLAPlugServer();
OlaSoftUpdateLastStatusReturn status = ola.SoftUpdateTryRecover("C:\\App");
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
status := ola.SoftUpdateTryRecover(`C:\App`)
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let status = ola.soft_update_try_recover(r"C:\App");
cpp
var ola = com("OlaPlug.OlaSoft")
var status = ola.SoftUpdateTryRecover("C:\App")
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
Set status = ola.SoftUpdateTryRecover("C:\App")
text
.局部变量 ola, OLAPlug
.局部变量 status, OlaSoftUpdateLastStatusReturn
ola.创建 ()
status = ola.SoftUpdateTryRecover(“C:\App”)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var json = ola.SoftUpdateTryRecover("C:\\App");
// Aardio SDK 返回 JSON 字符串,需自行解析
text
变量 ola <类型 = OLAPlugServer>
变量 status <类型 = OlaSoftUpdateLastStatusReturn>
ola = 新建 OLAPlugServer
status = ola.SoftUpdateTryRecover("C:\App")
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
OlaSoftUpdateLastStatusReturn status = ola.SoftUpdateTryRecover("C:\\App");

原生 DLL 调用

cpp
long ptr = SoftUpdateTryRecover("C:\\App");
if (ptr != 0) {
    char buffer[2048] = {0};
    GetStringFromPtr(ptr, buffer, sizeof(buffer));
    FreeStringPtr(ptr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long SoftUpdateTryRecover(string installRoot);

long ptr = SoftUpdateTryRecover(@"C:\App");
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    string result = sb.ToString();
}
python
from ctypes import CDLL, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ptr = ola.SoftUpdateTryRecover(b"C:\\App")
if ptr:
    buf = create_string_buffer(2048)
    ola.GetStringFromPtr(ptr, buf, 2048)
    ola.FreeStringPtr(ptr)
    result = buf.value.decode("utf-8")

返回值

调用方式返回值说明
SDKOlaSoftUpdateLastStatusReturn与 SoftUpdateGetLastStatus 相同结构
原生 DLL非 0成功,返回 JSON 字符串指针
原生 DLL0调用失败

注意事项

项目说明
适用范围主要用于 zip/rar 覆盖流程;exe 安装器的回滚依赖安装器自身。
backup 缺失若 flag 存在但 backup 缺失,将返回失败状态(Code=0 / StatusCode=0),需人工介入。
自动恢复SoftUpdateStart 开始时也会尝试一次自动恢复。
释放内存原生返回指针需 FreeStringPtr